import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class RunTimeGenerateComponent {
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setSize(200, 350);
		frame.setLayout(new GridLayout(4, 4));

		for (int i = 0; i < 16; i++) {
			JButton button = new JButton("" + i);
			button.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					System.out.println(((JButton) e.getSource()).getText());
				}
			});
			frame.add(button);

		}

		frame.setVisible(true);

	}
}
